package com.chenwenxuan.sync.console.service;

import org.apache.log4j.Logger;

import com.chenwenxuan.sync.console.dao.TaskArgDao;
import com.chenwenxuan.sync.console.dao.TaskDao;
import com.chenwenxuan.sync.console.dao.TaskMailDao;
import com.chenwenxuan.sync.console.dao.TaskRuntimeInfoDao;
import com.chenwenxuan.sync.console.model.Task;
import com.chenwenxuan.sync.console.model.TaskArgs;
import com.chenwenxuan.sync.console.model.TaskRuntimeInfo;

public class TaskInvokerService {
	
	private Logger logger = Logger.getLogger(TaskInvokerService.class);
	
	private TaskDao taskDao;
	private TaskArgDao taskArgDao;
	private TaskMailDao taskMailDao;
	private TaskRuntimeInfoDao taskRuntimeInfoDao;
	
	public TaskRuntimeInfoDao getTaskRuntimeInfoDao() {
		return taskRuntimeInfoDao;
	}

	public void setTaskRuntimeInfoDao(TaskRuntimeInfoDao taskRuntimeInfoDao) {
		this.taskRuntimeInfoDao = taskRuntimeInfoDao;
	}
	
	public TaskArgs getTaskArgs(Task task) {
		return taskArgDao.getTaskArgs(task.getTaskId());
	}

	public void updateTaskRuntimeInfo(Task task, TaskRuntimeInfo runtimeInfo) {
		taskDao.updateTaskLastExecute(task);
		taskRuntimeInfoDao.addRuntimeInfoEntry(runtimeInfo);
		if ( task.isDebugEnable() ) {
			taskRuntimeInfoDao.addDebugLogs(runtimeInfo);
		}
	}
	
	public TaskDao getTaskDao() {
		return taskDao;
	}
	public void setTaskDao(TaskDao taskDao) {
		this.taskDao = taskDao;
	}
	public TaskArgDao getTaskArgDao() {
		return taskArgDao;
	}
	public void setTaskArgDao(TaskArgDao taskArgDao) {
		this.taskArgDao = taskArgDao;
	}
	public TaskMailDao getTaskMailDao() {
		return taskMailDao;
	}
	public void setTaskMailDao(TaskMailDao taskMailDao) {
		this.taskMailDao = taskMailDao;
	}
}
